package com.tao.gulimall.ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mysql.cj.util.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tao.common.utils.PageUtils;
import com.tao.common.utils.Query;

import com.tao.gulimall.ware.dao.PurchaseDetailDao;
import com.tao.gulimall.ware.entity.PurchaseDetailEntity;
import com.tao.gulimall.ware.service.PurchaseDetailService;

import javax.annotation.Resource;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Resource
    private PurchaseDetailDao purchaseDetailDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        LambdaQueryWrapper<PurchaseDetailEntity> lqw = new LambdaQueryWrapper<>();

        String key = (String) params.get("key");
        if(!StringUtils.isNullOrEmpty(key)){
            lqw.and(item->{
                item.eq(PurchaseDetailEntity::getPurchaseId,key).or().eq(PurchaseDetailEntity::getSkuId,key);
            });
        }
        String status = (String) params.get("status");
        if (!StringUtils.isNullOrEmpty(status)){
            lqw.eq(PurchaseDetailEntity::getStatus,status);
        }
        String wareId = (String) params.get("wareId");
        if (!StringUtils.isNullOrEmpty(wareId)){
            lqw.eq(PurchaseDetailEntity::getWareId,wareId);
        }
        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                lqw
        );

        return new PageUtils(page);
    }

	@Override
	public List<PurchaseDetailEntity> seletListByPurchaseId(Long id) {
        LambdaQueryWrapper<PurchaseDetailEntity> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PurchaseDetailEntity::getPurchaseId, id);
		return purchaseDetailDao.selectList(lqw);
	}

}